package beans

/**
  * Created by hunter.coder 涛哥  
  * 2019/2/11 9:49
  * 交流qq:657270652
  * Version: 1.0
  * 更多学习资料：https://blog.csdn.net/coderblack/
  * Description:
  **/

import Utils.ProbUtil

import scala.beans.BeanProperty

//  一个用户，可以更改基本信息，可以换手机，可以换位置
class UserBean(val cookieid: String, var account:String, var email: String, var phoneNbr: String, var birthday: String, var isRegistered: Boolean, var isLogin: Boolean, var addr: String,
               var gender: String, var phone: Phone, var app: AppInfo, var loc: Location){

  @BeanProperty
  var sessionId:String = ""
  /**
    * 更换手机
    */
  def changePhone(): Unit ={
    if(ProbUtil.probilityDo(5)){
      this.phone = ProbUtil.phone
    }
  }

  /**
    * 更换位置
    */
  def changeLoc(): Unit = {
    if (ProbUtil.probilityDo(70)) {
    val loc = ProbUtil.location
    this.loc = loc
  }
  }

  /**
    * 更新app
    */
  def changeApp(): Unit ={
    if (ProbUtil.probilityDo(10)) {
      val newv = ProbUtil.appv
      this.app.setVer(newv) // 只有更高版本才能设置进去
    }

  }

  override def toString = s"UserBean(sessionId=$sessionId, id=$cookieid, account=$account, email=$email, phoneNbr=$phoneNbr, birthday=$birthday, isRegistered=$isRegistered, isLogin=$isLogin, addr=$addr, gender=$gender, phone=$phone, app=$app, loc=$loc)"
}

class Phone(val imei: String,
            var osName: String, // 操作系统名称： android   macos  apple
            var osVer: String, // 操作系统版本
            val resolution: String, var androidId: String, val manufacture: String, // 手机制造商
            val deviceId: String // 设备id，主要是苹果手机没有androidId
           ){

  override def toString = s"Phone(imei=$imei, osName=$osName, osVer=$osVer, resolution=$resolution, androidId=$androidId, manufacture=$manufacture, deviceId=$deviceId)"
}

class AppInfo(val appid: String, private var appVer: String, var release_ch: String, var promotion_ch: String) {

  def setVer(newVer: String): Unit = {
    if (newVer.compareTo(this.appVer) > 0) {
      this.appVer = newVer
    }
  }
  def getVer = this.appVer


  override def toString = s"AppInfo(appid=$appid, appVer=$appVer, release_ch=$release_ch, promotion_ch=$promotion_ch)"
}

class Location(var areacode:Int, var longtitude: Double, /* 经度 */ var latitude: Double, /*  纬度  */ var carrier: String, /* 运营商 */
               var netType: String, /* 移动网络类型： 3g  4g  wifi */ var cid_sn: String /* 基站编码 */ ,var ip:String ){

  override def toString = s"Location(areacode=$areacode, longtitude=$longtitude, latitude=$latitude, carrier=$carrier, netType=$netType, cid_sn=$cid_sn, ip=$ip)"
}

object UserEntities {
  def main(args: Array[String]): Unit = {
    val app = new AppInfo("com.51doit.mall.cup", "3.2.0", "小米应用", "头条推广")
    app.setVer("3.3.0")
    println(app.getVer)
  }


}


